package com.iflytek.web.mapper;

import com.iflytek.web.entity.User;
import com.iflytek.web.util.C3P0Util;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

public class UserMapper {

    private QueryRunner qr;

    public UserMapper() {
        qr = new QueryRunner(C3P0Util.getDataSource());
    }


    /**
     * 根据账号和密码获取用户对象
     *
     * @param account  账号
     * @param password 密码
     * @return
     * @throws SQLException
     */
    public User getByAccountAndPwd(String account, String password) {
        String sql = "SELECT * from `user` WHERE account=? and password=?";
        User user = null;
        try {
            user = qr.query(sql, new BeanHandler<>(User.class), account, password);
        } catch (SQLException e) {
            System.out.println(e.getStackTrace());
        }
        return user;
    }

}
